import { ipcRenderer } from 'electron'
import { IpcEvent } from 'app/type'

// 执行electron代码
export function actionCode(fnStr: string) {
    return ipcRenderer.invoke(IpcEvent.APP_ACTION_CODE, fnStr)
}
// 环境变量
class Process {
    get platform() {
        return process.platform
    }
    get env() {
        return process.env
    }
    get versions() {
        return process.versions
    }
    get type() {
        return 'renderer'
    }
    cwd() {
        return process.cwd()
    }
    crash() {
        return process.crash()
    }
}
// 状态栏设置
class Tray {
    static setImage(option: { light: string; dark: string }) {
        return ipcRenderer.invoke(IpcEvent.TRAY_SET_IMAGE, JSON.stringify(option))
    }
    static setTitle(title: string) {
        return ipcRenderer.invoke(IpcEvent.TRAY_SET_TITLE, title)
    }
    static setTooltip(tooltip: string) {
        return ipcRenderer.invoke(IpcEvent.TRAY_SET_TOOLTIP, tooltip)
    }
    static setTrayMenu(menuList: any[]) {
        return ipcRenderer.invoke(IpcEvent.TRAY_SET_CONTEXT_MENU, JSON.stringify(menuList))
    }
}
export function invoke(e: IpcEvent, ...args: any[]) {
    return ipcRenderer.invoke(e, ...args)
}
export function send(e: IpcEvent, ...args: any[]) {
    return ipcRenderer.send(e, ...args)
}
// 退出应用
export function quit() {
    return ipcRenderer.send(IpcEvent.APP_EXIT)
}

export { ipcRenderer, Process, Tray }
